package com.itheima.travel;

import com.itheima.travel.config.SpringConfig;
import com.itheima.travel.config.SpringMvcConfig;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import javax.servlet.FilterRegistration;
import javax.servlet.ServletException;

@SuppressWarnings("ALL")
/**
 * @Description :web.xml配置类
 * @author     :LD
 */
public class WebXmlConfig extends AbstractAnnotationConfigDispatcherServletInitializer {
    /**
     * 编码过滤器
     */
    @Override
    public void onStartup(javax.servlet.ServletContext servletContext) throws ServletException {
        //注册编码
        FilterRegistration.Dynamic characterEncoding = servletContext.addFilter("characterEncoding", new CharacterEncodingFilter());
        //初始参数
        characterEncoding.setInitParameter("encoding","UTF-8");
        //过滤路径
        characterEncoding.addMappingForUrlPatterns(null,false,"/*");
        super.onStartup(servletContext);
    }

    /**
     * 引入spring配置类
     */
    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[]{SpringConfig.class};
    }

    /**
     * 引入springmvc配置类
     */
    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[]{SpringMvcConfig.class};
    }

    /**
     * dispatcherServlet的拦截路径配置
     */
    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }
}
